All Questions
21 questions
0votes
1answer
127views
Correct way to deduplicate conditional statements [closed]
I'm facing with problem that in every function (with serves as service for endpoint) I need to check what is value of query parameter (mode). I need to check it on many callables, E.g. def create(self,...
1vote
2answers
196views
Should I add functionality by adding a new method to a class - or should I "register" the new functionality into a data structure?
I have one large class that computes ~50 different metrics (each metric has no side effects). My code is similar to this: class ReportingMetrics: def __init__(self, data:pd.DataFrame, config:dict)...
1vote
1answer
38views
Register a collection of tested object and get one configuraton out of it
I have a yml configuration file that list multiple application. Each application can contain multiple configuration. And of course each configuration can contain multiple mode apps: - name: foo ...
1vote
1answer
4kviews
Using isinstance() during exception handling for subsequent action
I've read various posts that polymorphism should be used instead of isinstance, and I agree that makes sense when the use of isinstance is checking the subtypes of a class to determine what to do. ...
-1votes
1answer
164views
How would you design the abstraction/class(es)/component(s) of a third-party service/api used in your application?
Lets say you were designing a Twitter client for people with people could see tweets and post tweets? How would you design the twitter api abstraction? Many of the api wrappers I've seen feature an ...
2votes
0answers
69views
How to interface with very badly written code in Python? [duplicate]
I have to extend some very badly written Python code (no documentation, very interdependent, barely any encapsulation, very static, everything hard-coded, etc..) and therefore do I obviously have to ...
0votes
1answer
63views
Method grouping other methods of the same family and how to call any of these separately
Worse title ever but I don't really know how to describe my scenario in a line... So I have a method that wraps the calls of a many methods of the same nature. Once any of these methods have finished,...
1vote
2answers
101views
__init__ arguments differ from object attributes
Is the following class definition a good design? class Myclass: def __init__(self,num1,num2): self.complicated_tree = __class__.object_creator(num1,num2) @classmethod def ...
4votes
1answer
2kviews
Python class naming: nested classes or composed names?
I encountered a scenario where I cannot decide on which is the best (or worst) naming strategy. The context is the following: a bracket (as in a tournament) made up of nodes, where is node is made up ...
1vote
3answers
2kviews
Is isinstance a good way of identifying the type of an object?
I have a bunch of classes inheriting from Violation. These subclasses model violations to different rules: UsedTimeslot, TeamConstraint, etc... I need to check what kind of violation happened in ...
0votes
1answer
71views
Redesign factory to throw error on load time instead of on execution time
I am using a factory pattern to get objects that shouldn't be instantiated other than the factory class. These objects are of type ViolationType, which represent violations on a set of rule. Here is ...
0votes
1answer
48views
Categories with fixed choices design
I need to make a category/type class to identify an object. The usual way to do it is just pass a string to initialize a new category: category = Category('A') obj = Object(category) However, the set ...
2votes
1answer
96views
Scheduling rule violation design
In the context of sports scheduling, a scheduling rule violation (let's call it simply violation from now on) is produced when trying to allocate a match in an illegal timeslot. There is a wide ...
7votes
2answers
3kviews
self vs super() "inconsistency" in Python
According to Python documentation, super() can be used without arguments inside class definitions, because the compiler implicitly feeds it with contextual arguments: class C(B): def method(self, ...
8votes
3answers
2kviews
Refactoring of a client API for avoid duplicated code and unclear passage of parameters
I need to develop an API, the functions of the API are requests that call the service exposed by a server. Initially the API worked like this: class Server: def firstRequest(self, arg1, arg2): ...